<?php

namespace App\Admin\Controllers;

use App\Admin\Renderable\Players;
use App\Admin\Repositories\Course;
use App\Models\Seting;
use App\Models\Team;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Grid\Row;
use Illuminate\Support\Collection;

class SetingController  extends AdminController
{
    private $uid = '';
    public function index(Content $content)
    {
        return $content->title('基本设置')
            ->description('列表')
            ->body($this->grid());
    }

    public function create(Content $content)
    {
        return $content->title('基本设置')
            ->description('创建')
            ->body($this->form());
    }

    protected function grid()
    {
        return Grid::make(new Seting(), function (Grid $grid) {


             $grid->column('key');
             $grid->column('value')->display(function ($value){
                 if ($this->id == 1){
                     $res = json_decode($value, true);
                     if ($res){
                         static $a = '';
                         $len = (count($res));
                         for ($i=0;$i<$len;$i++){
                             $a.= "<span><img  src=".config('alioss.ossServer').'/'.json_decode($value)[$i]." width='100'></img><span>&nbsp; &nbsp; ";
                         }
                         return $a;
                     }else{
                         return '';
                     }
                 }
                 return $value;
             });
            $grid->actions(function (Grid\Displayers\Actions $actions) {
//                $actions->disableDelete();
//                $actions->disableEdit();
//                $actions->disableQuickEidt();
                $actions->disableView();
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Seting(), function (Form $form) {
            $form->display('id');
            $form->text('key');
            if ($form->getKey() == 1){
                $form->multipleFile('value','精彩图集')->saving(function ($paths) {
                    // 也可以转化为json
                    return json_encode($paths);
                })->autoUpload()->uniqueName();
            }else{
                $form->text('value');
            }
        });
    }
}
